<div class="row-fluid">
    <div class="box span12">
        <div class="box-header" data-original-title>
            <h2>Extra Item</h2>
        </div>
        <div class="box-content">
            <?php if (Yii::app()->user->hasFlash('error')): ?>
                <div class="alert alert-error">
                    <button type="button" class="close" data-dismiss="alert">×</button>
                    <?php echo Yii::app()->user->getFlash('error'); ?>
                </div>
            <?php endif; ?>
            <div class="table-responsive"> 
                <table class="table table-bordered table-striped table-condensed">
                    <thead>
                    <th>Name</th>
                    <th>Duration</th>
                    <th>Price</th>
                    <th></th>
                    </thead>
                    <tbody id="list_item">
                        <?php if ($model->extraServices): ?>
                            <?php foreach ($model->extraServices as $exSv): ?>
                                <tr>

                                    <td><?php echo CHtml::textField("ExtraService[$exSv->id][name]", $exSv->name, array('placeHolder' => 'Type name')) ?></td>
                                    <td><?php echo CHtml::dropDownList("ExtraService[$exSv->id][duration]", $exSv->duration, Service::getDurationArray()) ?></td>
                                    <td>
                                        From
                                        <div class="input-prepend">
                                            <span class="add-on">$</span>
                                            <?php echo CHtml::textField("ExtraService[$exSv->id][from_price]", $exSv->from_price, array('class' => 'input-small')) ?>
                                        </div>
                                        to
                                        <div class="input-prepend">
                                            <span class="add-on">$</span>
                                            <?php echo CHtml::textField("ExtraService[$exSv->id][to_price]", $exSv->to_price, array('class' => 'input-small')) ?>
                                        </div>
                                    </td>
                                    <td><a class="btn" onclick="deleteExtraItem('<?php echo Yii::app()->createUrl('service/deleteExtraitem', array('id' => $exSv->id)) ?>')">
                                            <i class="icon-remove-sign"></i>&nbsp;Delete item</a></td>
                                </tr>
                            <?php endforeach; ?>
                        <?php endif; ?>
                        <?php echo $this->renderPartial('extra/item') ?>
                    </tbody>
                </table>
            </div>
            <div class="box-btn">
                <a class="btn btn-success" onclick="addItem()" id="add_retail_product"><i class="icon-plus-sign-alt"></i>&nbsp;Add Item</a>
            </div>
        </div>
    </div>
</div>
<script>
    function addItem()
    {
        $.ajax({
            url: '<?php echo Yii::app()->createUrl('Service/GenExtraRow') ?>',
            type: 'POST',
        }).done(function(html) {
            $('#list_item').append(html);
        });
    }
    function deleteExtraItem(url)
    {
        if (confirm('Are you sure delete this item?'))
            window.location = url;
        return false;
    }
</script>